package com.eyas.business.controllor.login;

import com.eyas.business.service.login.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Auther: 王龙龙
 * @Date: 2019/2/26 11:32
 * @Description:
 */
@Controller
@RequestMapping("/eyas/admin/")
public class LoginAction {
    @Autowired
    private LoginService loginService;


    @PostMapping("/login")
    @ResponseBody
    public String login(String username, String password, HttpServletRequest request) {
        String result = loginService.login(request,username,password);
        return result;
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "redirect:/eyas/pagegoto/login";
    }

    @RequestMapping(value = "/modifypwd",method = RequestMethod.PUT)
    @ResponseBody
    public String modifypwd(String pwdold,String pwdnew,HttpSession session) {
        String result = loginService.modifypwd(pwdold,pwdnew,session);
        return result;
    }
}
